package com.roncoo.student.stu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.roncoo.student.stu.entity.Lecturer;
import com.roncoo.student.stu.entity.LecturerAudit;
import com.roncoo.student.stu.dao.LecturerAuditMapper;
import com.roncoo.student.stu.entity.OrderInfo;
import com.roncoo.student.stu.entity.User;
import com.roncoo.student.stu.service.ILecturerAuditService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author jl
 * @since 2021-03-24
 */
@Service
public class LecturerAuditServiceImpl extends ServiceImpl<LecturerAuditMapper, LecturerAudit> implements ILecturerAuditService {


    @Resource
    private LecturerAuditMapper lecturerAuditMapper;

    @Override
    public Page select(Lecturer lecturer, OrderInfo orderInfo, LecturerAudit lecturerAudit, Page page) {

        QueryWrapper wrapper = new QueryWrapper<>();

        //wrapper.like("lecturerName", lecturerAudit.getLecturerName());

        if (StringUtils.isNotBlank(lecturerAudit.getLecturerUserName())) {
            wrapper.like("a.lecturer_user_name", lecturerAudit.getLecturerUserName());
        }

        if (lecturerAudit.getAuditStatus() != null) {
            wrapper.like("a.audit_status", lecturerAudit.getAuditStatus());
        }

        System.out.println(lecturerAudit);

        return lecturerAuditMapper.select(page, lecturer, orderInfo, lecturerAudit, wrapper);
//        return lecturerAuditMapper.select(lecturer, orderInfo, page, wrapper);

    }

    @Override
    public Page finAll(LecturerAudit lecturerAudit,  Page page) {


        QueryWrapper wrapper = new QueryWrapper<>();


        if (StringUtils.isNotBlank(lecturerAudit.getLecturerUserName())) {
            wrapper.like("a.lecturer_user_name",lecturerAudit.getLecturerUserName());
        }
        if (StringUtils.isNotBlank(lecturerAudit.getLecturerPhone())) {
            wrapper.like("a.lecturer_phone",lecturerAudit.getLecturerPhone());
        }
        if (lecturerAudit.getAuditStatus() != "") {
            wrapper.eq("a.audit_status", lecturerAudit.getAuditStatus());
        }

        Page page1 = lecturerAuditMapper.findAll(page, lecturerAudit,  wrapper);


        return page1;
    }

    @Override
    public Boolean addTeacher(LecturerAudit lecturerAudit) {


        return lecturerAuditMapper.addTeacher(lecturerAudit);
    }

    @Override
    public boolean judgeAdd(String lecturerPhone) {
        List<LecturerAudit> qwe = lecturerAuditMapper.judgeAdd(lecturerPhone);
        if (qwe.size()==0){
            return true;
        }else {
            return false;
        }
    }
}
